<template>
  <div class="dashboard-container">
<!--    <component :is="currentRole" /> -->
    <div v-loading="listLoading" style="background-color: #404855;min-height: 1100px;">

          <el-dialog :visible.sync="dialogTableVisible" :title="'当前设备: 设备 '+curResInfo.Name+ ' ['+curResInfo.MEQG_Name+']'" >

            <!-- 以下是设备 Lot_Start选项-->
            <div class="dialoglotStart"  v-if="curResInfo.U_MLOT == '' || curResInfo.U_MLOT == 'wait'">
              <el-form ref="form" :model="curResForm" label-width="80px" style="width:700px;margin-left:30px;">
                <el-form-item v-if="curResInfo.MEQG_Code == 'TB' || curResInfo.MEQG_Code == 'HJ'" label="产品名称">
                  <el-input v-model="curResForm.name" style="width:200px" ></el-input>
                </el-form-item>
<!--                <el-form-item v-if="curResInfo.MEQG_Code == 'TB' || curResInfo.MEQG_Code == 'HJ'" label="产品数量">
                  <el-input type='number' v-model="curResForm.qty" min='1' style="width:200px" ></el-input>
                </el-form-item> -->
                <div v-if="curResInfo.MEQG_Code == 'HJ' || curResInfo.MEQG_Code == 'TB'" v-for="(item,index) in lots" :key="index" >
                  <el-form-item :label="'产品批次'+ (index+1)" :inline="true">
                    <el-input v-model="item.U_MLOO" style="width:200px" ></el-input>
                    <el-button v-if="index == 0" type="success" @click="lots.push({'U_MLOO':'','LineId': lots.length+1})" icon="el-icon-plus" style="margin-left:10px;"></el-button>
                    <el-button v-else type="danger" @click="lots.splice(index, 1)" icon="el-icon-minus" style="margin-left:10px;"></el-button>
                  </el-form-item>
                </div>

                <el-table v-show="curResInfo.MEQG_Code == 'SH'" :default-sort = "{prop: 'CreateDate', order: 'ascending'}" @sort-change="sortChangeSH" v-loading="tableLoadingSH" ref="multipleTable" :data="shWaitingLots" :height="shWaitingLots.length>9 ? 450 : (shWaitingLots.length<5 ? 250 : shWaitingLots.length*50 ) " tooltip-effect="dark" border fit highlight-current-row @selection-change="handleSelectionChangeSH" style="width: 100%;margin-bottom:10px;" >
                  <el-table-column type="selection" width="40">
                  </el-table-column>
                  <el-table-column v-if="false" align="center" label="DocEntry" width="100">
                    <template slot-scope="scope">
                      <span>{{ scope.row.DocEntry }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column width="100px" align="center" label="设备编号">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_MEQU }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column min-width="120px" align="center" label="生产批号">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_MLOO }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column min-width="100px" align="center" prop="U_ItemCode" sortable label="产品">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_ItemCode }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column min-width="80px" align="center" label="数量">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_Qty }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column align="center" label="日期" prop="CreateDate" sortable width="100">
                    <template slot-scope="scope">
                      <span>{{ scope.row.CreateDate }}</span>
                    </template>
                  </el-table-column>

                </el-table>

                <el-table v-show="curResInfo.MEQG_Code == 'FQ'" :default-sort = "{prop: 'CreateDate', order: 'ascending'}" @sort-change="sortChangeFQ" v-loading="tableLoadingFQ" ref="singleTable" :data="fqWaitingLots" :height="fqWaitingLots.length>9 ? 450 : (fqWaitingLots.length<5 ? 250 : fqWaitingLots.length*50 ) " border fit highlight-current-row @current-change="handleSelectionChangeFQ" style="width: 100%;margin-bottom:10px;">
                  <el-table-column type="index" width="40">
                  </el-table-column>
                  <el-table-column v-if="false" align="center" label="单据号" width="100">
                    <template slot-scope="scope">
                      <span>{{ scope.row.DocEntry }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column width="100px" align="center" label="设备编号">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_MEQU }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column min-width="120px" align="center" label="生产批号">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_MLOO }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column min-width="100px" align="center" prop="U_ItemCode" sortable label="产品">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_ItemCode }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column min-width="80px" align="center" label="数量">
                    <template slot-scope="scope">
                      <span>{{ scope.row.U_Qty }}</span>
                    </template>
                  </el-table-column>

                  <el-table-column align="center" label="日期" prop="CreateDate" sortable width="100">
                    <template slot-scope="scope">
                      <span>{{ scope.row.CreateDate }}</span>
                    </template>
                  </el-table-column>

                </el-table>

                <el-form-item style="margin-top: 20px;margin-bottom: 0px;">
                  <el-button type="primary" @click="onSubmitLotStart(curResInfo.MEQG_Code)" :disabled="(curResInfo.MEQG_Code == 'FQ' && fqSelLots.length == 0) || (curResInfo.MEQG_Code == 'SH' && shSelLots.length == 0) || ((curResInfo.MEQG_Code == 'HJ' || curResInfo.MEQG_Code == 'TB') && lots.map(v=>v.U_MLOO.trim()).filter(v=>v.length>0).join(',').length == 0)">提交</el-button>
                  <el-button v-if="false" type="success" @click="addInputMLOO">批次栏位添加</el-button>
                  <el-button type="warning" @click="onSubmitResStop">临时停机</el-button>
                  <el-button @click="()=>{this.dialogTableVisible = false; this.curResForm = {name:'',lot_id:''};this.fqSelLots=[];this.shSelLots=[];}">取消</el-button>
                </el-form-item>
              </el-form>
            </div>

            <!-- 以下是设备 Lot_End选项-->
            <div v-if="curResInfo.U_MLOT == 'running'">
              <el-form ref="form" :model="curResForm" label-width="120px" style="width:400px;">
                <el-form-item v-for="item in curResForm.lots" :key="item.LineId" :label="'产品批次 '+(curResForm.lots>1?item.LineId:'')">
                  <el-input v-model="item.U_MLOO" disabled></el-input>
                </el-form-item>
                <el-form-item label="产品名称">
                  <el-input v-model="curResForm.name" disabled></el-input>
                </el-form-item>
                <el-form-item label="产出数量">
                  <el-input type='number' v-model="curResForm.qty" min='1' :disabled="curResInfo.MEQG_Code == 'SH' || curResInfo.MEQG_Code == 'FQ'"></el-input>
                </el-form-item>
               <el-form-item v-if="curResInfo.MEQG_Code == 'TB'" label="投入数量">
                  <el-input type='number' v-model="curResForm.inqty" min='1'></el-input>
                </el-form-item>
                <el-form-item v-if="curResInfo.MEQG_Code == 'TB'" label="是否需要熟化" label-width="120px">
                  <el-radio-group v-model="rdoProcessToSH">
                    <el-radio label='Y'>是</el-radio>
                    <el-radio label='N'>否</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="onSubmitLotEnd(false)">提交</el-button>
                  <el-button v-if="curResInfo.MEQG_Code == 'FQ'" @click="onSubmitLotEnd(true)" type="success">部分分切</el-button>
                  <el-button @click="dialogTableVisible = false;">取消</el-button>
                </el-form-item>
              </el-form>
            </div>

            <!-- 以下是设备 开机选项-->
            <div v-if="curResInfo.U_MLOT == 'halt'">
              <el-form ref="form" :model="curResForm.prods" label-width="80px" style="width:400px;">
                <el-form-item>
                  <el-button type="primary" @click="onSubmitResStart">开机</el-button>
                  <el-button @click="()=>{dialogTableVisible = false;}">取消</el-button>
                </el-form-item>
              </el-form>
            </div>

          </el-dialog>

          <div style="display: flex;justify-content:space-between;padding-top:20px;margin:0 70px 20px 70px;border-bottom:2px solid gray;justify-items:center;eight: 30px;line-height: 30px;">
            <div style="color:#fff;margin-right:54px;margin-bottom: 10px;font-size: 30px;font-weight: bold;">SMART MES</div>
            <div style="color:#fff;margin-right:14px;margin-bottom: 10px;font-size: 28px;font-weight: bold;">
              {{ currentTime.year }}/{{ currentTime.month }}/{{ currentTime.day }}  {{ currentTime.hour }} : {{ currentTime.minute }} : {{ currentTime.second }}
            </div>
          </div>
          <div style="display: flex;justify-content: end;margin-right:80px;justify-items:center;eight: 30px;line-height: 30px;">
            <div style="width:30px;height:30px;background-color: #5ba13a;margin-right:6px;"> </div>
            <div style="color:#fff;margin-right:16px;">开机</div>
            <div style="width:30px;height:30px;background-color: #E6A23C;margin-right:6px;"> </div>
            <div style="color:#fff;margin-right:16px;">待机</div>
            <div style="width:30px;height:30px;background-color: #909399;margin-right:6px;"> </div>
            <div style="color:#fff;">停机</div>
          </div>
        <div class="components-container board">
          <div class="board-column" v-for="(item,index) in list">
            <div class="board-column-header" style="font-size:20px;font-weight: bold;background-color: #404855;">
              {{ opers[index] }}工程
            </div>
            <div class="board-column-content" >
              <div v-for="(subitm,idx) in item" :key="subitm.id" @click="handleClick(subitm,index,idx)">
                <div v-if="subitm.U_MLOT == 'running'" class="board-item"  style="background-color:#5ba13a;background: radial-gradient(circle at center, #5ba13a, green 100%, rgba(0,0,0,0));text-align: center;border-radius: 10px;color:#20252b;font-size:20px;width: 320px;">
                  {{ subitm.Name }}
                  <i class="el-icon-cpu" style="color:#FFF;font-size: 16px;margin-left:8px;"></i>
                  <span style="font-size: 16px;color:#FFF;"> {{ subitm.prodMatId.length>10 ? subitm.prodMatId.substring(0,10)+'...' : subitm.prodMatId }} </span>
                  <i v-if="false" class="el-icon-loading" style="color:#FFF;font-size: 16px;"></i>
                </div>
                <div v-else-if="subitm.U_MLOT == 'wait' || subitm.U_MLOT == ''" class="board-item" style="background-color:#E6A23C;background: radial-gradient(circle at center, #E6A23C, #de7f08 100%, rgba(0,0,0,0));text-align: center;border-radius: 10px;color:#20252b;font-size:20px;width: 320px;">
                    {{ subitm.Name }}
                </div>
                <div v-else class="board-item" style="background-color:#909399;background: radial-gradient(circle at center, #909399, gray 100%, rgba(0,0,0,0));text-align: center;border-radius: 10px;color:#20252b;font-size:20px;width: 320px;">
                    {{ subitm.Name }}
                </div>
              </div>
            </div>
          </div>

        </div>

      </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import editorDashboard from './editor'
import axios from 'axios'
import { getUserInfo } from '@/utils/auth'
import { getWaitingProdList, getLastMPCPByResID, fetchAllResStatus, fetchSingleMLOOsByDocEntry, fetchSHWaitingLOTs, fetchFQWaitingLOTs, fetchOpers, processMPCPs, fetchSingleResMPCPDetail, processResStartMPCPs, processResEndMPCPs, fetchCommonList, fetchTBMPCPDocEntryByMLOO } from '@/api/res'

export default {
  name: 'Dashboard',
  components: { adminDashboard, editorDashboard},
  data() {
    return {
      currentRole: 'adminDashboard',
      group: 'operation',
      opers:[],
      listLoading: true,
      dialogTableVisible: false,
      options: [
        { value: '选项1', label: '开机' },
        { value: '选项2', label: '停机' }
      ],
      value: '',
      curResInfo:{
        oper_id:'',
        res_id:''
      },
      lots:[],
      list:[],
      curResForm:{},
      currentTime:{},
      userInfoRoles:[],
      skipProcessSHradio:'N',
      rdoProcessToSH: 'Y',
      tableLoadingSH:false,
      tableLoadingFQ:false,
      shWaitingLots:[],
      shSelLots:[],
      fqWaitingLots:[],
      fqSelLots:[],
      fqSelLotTBZLExistFlag:false,
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    this.currentTime = { hour: 0, minute: 0, second: 0 }

    this.listLoading = true

    fetchOpers().then(res=>{
      this.opers = res.map(v=> v.Name)
      console.log('fetchOpers0-------------',res.map(v=> v.Name))
      fetchAllResStatus().then(res=>{
        this.list = res
        this.listLoading = false
        console.log('fetchAllResStatus0------',res)
      }).catch(err=>{
        this.listLoading = false
        console.log(err)
      })
    }).catch(err=>{
        this.listLoading = false
        console.log(err)
    })
  },
  mounted() {
    var _userInfo = JSON.parse(getUserInfo())
    this.userInfoRoles = JSON.parse(_userInfo.U_Menu).role

     let timer = setInterval(() => {
        const now = new Date()
        this.currentTime = {
          year: now.getFullYear().toString().padStart(4, '0'),
          month : (now.getMonth() + 1).toString().padStart(2, '0'),
          day : now.getDate().toString().padStart(2, '0'),
          hour: now.getHours().toString().padStart(2, '0'),
          minute: now.getMinutes().toString().padStart(2, '0'),
          second: now.getSeconds().toString().padStart(2, '0')
        }
      }, 1000);

    //同步所有设备状态
    let sytimer = setInterval(() => {
        fetchAllResStatus().then(res=>{
          this.list = res
        }).catch(err=>{
          this.listLoading = false
          console.log(err)
        })
      }, 10000);


      // 离开当前页面时销毁定时器
      this.$once('hook:beforeDestroy', () => {
        clearInterval(timer);
        timer = null;
        clearInterval(sytimer);
        sytimer = null;
      })
  },
  methods: {
      sortChangeFQ({ column }){
        const lots = this.fqWaitingLots
        var sort = column.order;      // ascending 升序、descending 降序、 null 默认排序
        var sortName = column.label;  //当前表头名称
        if (column.label == '日期') {
          if(sort == 'descending'){
            this.fqWaitingLots = lots.sort((a,b)=>b.CreateDate.localeCompare(a.CreateDate))
          }else{
            this.fqWaitingLots = lots.sort((a,b)=>a.CreateDate.localeCompare(b.CreateDate))
          }
        }

        if (column.label == '产品') {
          if(sort == 'descending'){
            this.fqWaitingLots = lots.sort((a,b)=>b.U_ItemCode.localeCompare(a.U_ItemCode))
          }else{
            this.fqWaitingLots = lots.sort((a,b)=>a.U_ItemCode.localeCompare(b.U_ItemCode))
          }
        }

      },
      sortChangeSH({ column }){
        const lots = this.shWaitingLots
        var sort = column.order;      // ascending 升序、descending 降序、 null 默认排序
        var sortName = column.label;  //当前表头名称
        if (column.label == '日期') {
          if(sort == 'descending'){
            this.shWaitingLots = lots.sort((a,b)=>b.CreateDate.localeCompare(a.CreateDate))
          }else{
            this.shWaitingLots = lots.sort((a,b)=>a.CreateDate.localeCompare(b.CreateDate))
          }
        }

        if (column.label == '产品') {
          if(sort == 'descending'){
            this.shWaitingLots = lots.sort((a,b)=>b.U_ItemCode.localeCompare(a.U_ItemCode))
          }else{
            this.shWaitingLots = lots.sort((a,b)=>a.U_ItemCode.localeCompare(b.U_ItemCode))
          }
        }

      },
      handleSelectionChangeSH(val){
        console.log('handleSelectionChangeSH-----',val)
        this.shSelLots = val
        //this.shSelLots = val.map(v=>v.U_MLOO)
      },
      handleSelectionChangeFQ(val){
        if(val != null && val.U_MLOO != null){
          this.fqSelLots = [val]
          fetchTBMPCPDocEntryByMLOO({ U_MLOO : val.U_MLOO}).then(res=>{
            this.fqSelLotTBZLExistFlag = res==0 ? false : true
            console.log('handleSelectionChangeFQ-----',this.fqSelLots,res,this.fqSelLotTBZLExistFlag)
          })
        }
      },

      checkProductionRole(MEQG){
        //console.log('checkProductionRole--------',MEQG,this.userInfoRoles.filter(v=>v.substr(0,1)=='M'))
        var _role = false
        if(MEQG == 'HJ' && this.userInfoRoles.indexOf('M1') >= 0) //混胶 ->M1, 涂布 ->M2, 熟化/分切 -> M3
        {
          _role = true
        }
        else if(MEQG == 'TB' && this.userInfoRoles.indexOf('M2') >= 0)
        {
          _role = true
        }
        else if((MEQG == 'SH' || MEQG == 'FQ') && this.userInfoRoles.indexOf('M3') >= 0)
        {
          _role = true
        }

        return _role
      },

      handleClick(item,operId,resId) {
        this.curResInfo = JSON.parse(JSON.stringify(item))

        if(this.checkProductionRole(this.curResInfo.MEQG_Code)){

          this.curResInfo.oper_id = operId
          this.curResInfo.res_id = resId

          if(item.U_MLOT == 'halt'){
            this.dialogTableVisible = true
            console.log('当前设备状态:'+ '停机',this.curResForm)
            //fs.writeFileSync('log.txt', '['+new Date().toLocaleString()+'] 当前设备状态:停机'+JSON.stringify(this.curResForm)+'\r\n');
          }else if(item.U_MLOT == '' || item.U_MLOT == 'wait'){
            this.dialogTableVisible = true
            this.curResForm = {name:'', lot_id:'', qty:'', status:'wait'}
            this.lots = [{'U_MLOO':'','LineId':1}]
            console.log('当前设备状态:'+ '待机',this.curResForm,this.curResInfo)

            if(this.curResInfo.MEQG_Code == 'SH'){
              this.tableLoadingSH = true
              this.shSelLots = []

              getWaitingProdList({'U_Ostate':'G_SH'}).then(res=>{
                console.log('getWaitingProdList--SH-------',res)
                this.shWaitingLots = res.sort((a,b)=>{
                  if(a.CreateDate != b.CreateDate) return a.CreateDate.localeCompare(b.CreateDate)
                  if(a.U_ItemCode != b.U_ItemCode) return a.U_ItemCode.localeCompare(b.U_ItemCode)
                  return a.U_MEQU.localeCompare(b.U_MEQU)
                })
                this.tableLoadingSH = false
                console.log('fetchSHWaitingLOTs-------------', res)
              })

              /*
              fetchSHWaitingLOTs({page:1, limit:20}).then(res=>{
                // if(res.length==0){
                //   res = [
                //     {'DocEntry':101,'U_MEQU':'C1','U_MLOO':'ASD-01','U_ItemCode':'测试','U_Qty':'100','CreateDate':'2023-09-11'},
                //     {'DocEntry':102,'U_MEQU':'C1','U_MLOO':'ASD-02','U_ItemCode':'测试','U_Qty':'100','CreateDate':'2023-09-11'},
                //     {'DocEntry':103,'U_MEQU':'C2','U_MLOO':'ASD-03','U_ItemCode':'测试','U_Qty':'100','CreateDate':'2023-09-11'},
                //     {'DocEntry':104,'U_MEQU':'C3','U_MLOO':'ASD-04','U_ItemCode':'测试','U_Qty':'100','CreateDate':'2023-09-11'},
                //     {'DocEntry':105,'U_MEQU':'C4','U_MLOO':'ASD-05','U_ItemCode':'测试','U_Qty':'100','CreateDate':'2023-09-11'},
                //   ]
                // }
                this.shWaitingLots = res.sort((a,b)=>{
                  if(a.CreateDate != b.CreateDate) return a.CreateDate.localeCompare(b.CreateDate)
                  if(a.U_ItemCode != b.U_ItemCode) return a.U_ItemCode.localeCompare(b.U_ItemCode)
                  return a.U_MEQU.localeCompare(b.U_MEQU)
                })
                this.tableLoadingSH = false
                console.log('fetchSHWaitingLOTs-------------', res)
              })*/
            }
            if(this.curResInfo.MEQG_Code == 'FQ'){
              this.tableLoadingFQ = true
              this.fqSelLots = []

              getWaitingProdList({'U_Ostate':'G_FQ'}).then(res=>{
                console.log('getWaitingProdList--FQ-------',res)
                this.fqWaitingLots = res.sort((a,b)=>{
                  if(a.CreateDate != b.CreateDate) return a.CreateDate.localeCompare(b.CreateDate)
                  if(a.U_ItemCode != b.U_ItemCode) return a.U_ItemCode.localeCompare(b.U_ItemCode)
                  return a.U_MEQU.localeCompare(b.U_MEQU)
                })
                this.tableLoadingFQ = false
                console.log('fetchFQWaitingLOTs-------------', res)
              })

              /*fetchFQWaitingLOTs({page:1, limit:20}).then(res=>{
                this.fqWaitingLots = res.sort((a,b)=>{
                  if(a.CreateDate != b.CreateDate) return a.CreateDate.localeCompare(b.CreateDate)
                  if(a.U_ItemCode != b.U_ItemCode) return a.U_ItemCode.localeCompare(b.U_ItemCode)
                  return a.U_MEQU.localeCompare(b.U_MEQU)
                })
                this.tableLoadingFQ = false
                console.log('fetchFQWaitingLOTs-------------', res)
              })*/
            }
          }else if(item.U_MLOT == 'running'){
            fetchSingleResMPCPDetail({Code:this.curResInfo.Code}).then(res=>{
              console.log('fetchSingleResMPCPDetail-----',res)
              const lastDocEntry = res[0].DocEntry
              var _totalQty = 0

              if(this.curResInfo.MEQG_Code == 'SH' || this.curResInfo.MEQG_Code == 'FQ'){
                fetchSingleMLOOsByDocEntry({DocEntry: lastDocEntry}).then(resData=>{
                  resData.forEach(item=>{
                    _totalQty += item.U_Qty*1
                  })

                  this.dialogTableVisible = true
                  this.curResForm =  this.curResInfo.works || {name:'', lot_id:'', qty:'', status:'wait'}
                  this.curResForm.lots = res
                  this.curResForm.name = this.curResInfo.prodMatId
                  this.curResForm.qty = _totalQty
                })
              }else{
                this.dialogTableVisible = true
                this.curResForm =  this.curResInfo.works || {name:'', lot_id:'', qty:'', status:'wait'}
                this.curResForm.lots = res
                this.curResForm.name = this.curResInfo.prodMatId
                this.curResForm.qty = this.curResInfo.prodQty
              }

              //this.curResForm.skipProcessSHradio = this.curResInfo.MEQG_Code == 'TB' ? 'N' : ''

            }).catch(err=>{
              console.log('fetchSingleResMPCPDetail err--------',err)
            })
            console.log('当前设备状态:'+ '生产中',this.curResForm,this.curResInfo)
          }else{
            console.log('当前设备状态:'+ '未知,请联系管理员确认')
          }

        }else{
          console.log('没有对应工程的权限--------',this.curResInfo.MEQG_Code,this.userInfoRoles.filter(v=>v.substr(0,1)=='M'))
          this.$notify({ title: '提示', message: '权限不足', type: 'warning', duration: 2000 })
        }

        //console.log('handleClick--------',operId,resId,this.curResForm)

      },

      onSubmitLotStart(MEQG_Code){
        var _resInfo = this.list[this.curResInfo.oper_id][this.curResInfo.res_id];
        var _lots = []
        if(MEQG_Code == 'SH'){
          _lots = this.shSelLots.map(v=>v.U_MLOO).filter(v=>v.trim().length>0)
          this.curResForm.name = Array.from(new Set(this.shSelLots.map(v=>v.U_ItemCode))).join(",")
          this.curResForm.qty = this.shSelLots.map(v=>v.U_Qty).filter(v=>v.trim().length>0).join(",")
          console.log('onSubmitLotStart---------SH', this.shSelLots,this.curResForm)
        }else if(MEQG_Code == 'FQ'){
          _lots = [].concat(this.fqSelLots[0].U_MLOO)
          this.curResForm.name = this.fqSelLots[0].U_ItemCode
          this.curResForm.qty = this.fqSelLots[0].U_Qty
          console.log('onSubmitLotStart---------FQ', _lots)

          //需要对当前的涂布批次进行涂布质量是否录入确认, 尚未录入的批次 提示需要先完成质量数据录入后才能进行分切操作
          // if(_lots.length>0 && this.fqSelLotTBZLExistFlag == false){
          //   this.$notify({ title: '提示', message: _lots[0]+'批次缺少涂布质量数据, 请录入后再入账', type: 'warning', duration: 2000 })
          //   return
          // }
        }
        else{
          _lots = this.lots.filter(v=>v.U_MLOO.trim().length>0).map(v=>v.U_MLOO.trim())

          if(this.curResForm.name.trim().length == 0){
            this.$notify({ title: '提示', message: '产品名称不能为空,请重新输入', type: 'warning', duration: 2000 })
            return
          }
        }

        if(_lots.length == 0){
          this.$notify({ title: '提示', message: '批次号码不能为空,请重新输入', type: 'warning', duration: 2000 })
        }else{
          var _config = {
            'U_MPCO': 'run',
            'U_MEQU': this.curResInfo.Code,
            'product_mat_id': this.curResForm.name,
            //'product_qty': this.curResForm.qty,
            'U_MLOO': _lots,
            'U_MEQG': MEQG_Code
          }

          console.log('submit!Lot para', _config);

          processMPCPs(_config).then(res=>{
            this.curResForm.U_MLOT = 'running';
            _resInfo.works = JSON.parse(JSON.stringify(this.curResForm))
            _resInfo.U_MLOT = 'running';
            this.dialogTableVisible = false;

            _resInfo.prodMatId = this.curResForm.name
            _resInfo.prodQty = this.curResForm.qty

            console.log('submit!Lot End', res);
            this.$notify({
              title: '提示',
              message: '提交成功_MPCP单据号:'+res.data.data,
              type: 'success',
              duration: 2000
            })
          }).catch(err=>{
            console.log('processMPCPs err---------',err)
            this.$notify({ title: '提示', message: err, type: 'warning', duration: 2000 })
            this.dialogTableVisible = false;
          })
        }
      },

      onSubmitLotEnd(keepfq=false){

        if((this.curResInfo.MEQG_Code == 'TB' || this.curResInfo.MEQG_Code == 'HJ') && this.curResForm.qty.trim().length == 0 ){
          this.$notify({ title: '提示', message: '产品数量不能为空,请重新输入', type: 'warning', duration: 2000 })
          return
        }

        var _config = {
          'U_MPCO': 'end',
          'U_MEQU': this.curResInfo.Code,
          'product_mat_id': this.curResForm.name,
          'product_qty': this.curResForm.qty,
          'product_inqty': this.curResForm.inqty ?? '',
          'U_MLOO': this.curResForm.lots.map(v=>v.U_MLOO.trim()),
          'U_MEQG': this.curResInfo.MEQG_Code,
          'keepfq': keepfq
        }

        if(this.curResInfo.MEQG_Code == 'TB'){
          //_config.U_OperParm = this.skipProcessSHradio
          _config.U_OperParm = this.rdoProcessToSH == 'Y' ? 'N' : 'Y'
        }

        console.log('submit!Lot para', _config);

        processMPCPs(_config).then(res=>{
          this.curResForm.U_MLOT = 'wait';
          var _resInfo = this.list[this.curResInfo.oper_id][this.curResInfo.res_id];
          _resInfo.U_MLOT = 'wait';
          _resInfo.works = {}
          this.dialogTableVisible = false;
          console.log('submit!Lot End', res.data);
          this.$notify({
            title: '提示',
            message: '提交成功_MPCP单据号:'+res.data.data,
            type: 'success',
            duration: 2000
          })
        }).catch(err=>{
          console.log('processMPCPs err---------',err)
          this.$notify({
            title: '提示',
            message: err,
            type: 'warning',
            duration: 2000
          })
          this.dialogTableVisible = false;
        })

      },

      onSubmitResStop(){
        var that = this;
        //that.dialogTableVisible = false;
        //this.$notify({ title: '提示', message: '功能还在开发中', type: 'warning', duration: 2000 })
        console.log('onSubmitResStop-----', this.curResInfo)
        that.$confirm('确定要停机吗?', 'Warning', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(async() => {
            processResEndMPCPs({
              'U_MEQU': that.curResInfo.Code
            }).then(res=>{
              console.log('processResStartMPCPs-----',res)
              that.curResForm.U_MLOT = 'halt';
              that.list[this.curResInfo.oper_id][this.curResInfo.res_id].U_MLOT = 'halt';
              that.dialogTableVisible = false;
                that.$message({
                  type: 'success',
                  message: '停机操作成功!'
                })
            })
          })
          .catch(err => { console.error(err) })

        console.log('submit!Res Stop', this.curResForm);
      },

      onSubmitResStart(){
        var that = this;
        //that.dialogTableVisible = false;
        //this.$notify({ title: '提示', message: '功能还在开发中', type: 'warning', duration: 2000
        console.log('onSubmitResStart-----', this.curResInfo)
        that.$confirm('确定要开机吗?', 'Warning', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(async() => {
              processResStartMPCPs({
                'U_MEQU': that.curResInfo.Code
              }).then(res=>{
                console.log('processResStartMPCPs----',res)
                that.curResForm.U_MLOT = 'wait';
                that.list[this.curResInfo.oper_id][this.curResInfo.res_id].U_MLOT = 'wait';
                that.dialogTableVisible = false;
                  that.$message({
                    type: 'success',
                    message: '开机操作成功!'
                  })
              })
          })
          .catch(err => { console.error(err) })

        console.log('submit!Res Start', this.curResForm);
      },

  },
}
</script>

<style lang="scss">
.board {
  // width: 1000px;
  margin-left: 20px;
  display: flex;
  justify-content: space-around;
  flex-direction: row;
  align-items: flex-start;
}

.dialoglotStart{
  .el-table td{
    padding: 4px 0;
  }
}

.board-column {
    min-width: 300px;
    min-height: 100px;
    height: auto;
    overflow: hidden;
    //background: #f0f0f0;
    border-radius: 3px;

    .board-column-header {
      height: 50px;
      line-height: 50px;
      overflow: hidden;
      padding: 0 20px;
      text-align: center;
      background: #333;
      color: #fff;
      border-radius: 3px 3px 0 0;
    }

    .board-column-content {
      height: auto;
      overflow: hidden;
      background: #333;
      border: 10px solid transparent;
      min-height: 60px;
      display: flex;
      justify-content: flex-start;
      flex-direction: column;
      align-items: center;
      border-radius: 1em;

      .board-item {
        cursor: pointer;
        width: 100%;
        height: 50px;
        margin: 5px 0;
        background-color: #fff;
        text-align: left;
        line-height: 40px;
        padding: 5px 10px;
        box-sizing: border-box;
        box-shadow: 0px 1px 3px 0 rgba(0, 0, 0, 0.2);
      }
    }
  }

.kanban {
  &.todo {
    .board-column-header {
      background: #333;
    }
    .board-column-content {
      background: #333;
    }
  }
  &.working {
    .board-column-header {
      background: #333;
    }
    .board-column-content {
      background: #333;
    }
  }
  &.done {
    .board-column-header {
      background: #333;
    }
    .board-column-content {
      background: #333;
    }
  }
  &.hold {
    .board-column-header {
      background: #333;
    }
    .board-column-content {
      background: #333;
    }
  }
}
</style>
